package com.ais.gaea.autoconfigure;

import com.ais.gaea.GaeaTemplate;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @author xuning
 * @date 2022/11/28
 **/
@Configuration(proxyBeanMethods = false)
@ConditionalOnSingleCandidate(DataSource.class)
@EnableConfigurationProperties(GaeaProperties.class)
@ConditionalOnBean(JdbcTemplate.class)
@AutoConfigureAfter({DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class})
public class GaeaAutoConfiguration {
    @Bean
    public GaeaTemplate gaeaTemplate(JdbcTemplate jdbcTemplate) {
        return new GaeaTemplate(jdbcTemplate);
    }

}
